package token

import (
	"context"
)

const LoginAccountKey = "login_account"

type LoginAccountUtil struct {
}

type LoginAccount struct {
	Id          int64  `json:"id,string"`
	AccountName string `json:"accountName"`
	Nickname    string `json:"nickname"`
	Phone       string `json:"phone"`
	Email       string `json:"email"`
	AccessToken string `json:"accessToken"`
	Expire      int    `json:"expire"`
}

func NewLoginAccountUtil() *LoginAccountUtil {
	return &LoginAccountUtil{}
}
func (util *LoginAccountUtil) CurrentAccount(ctx context.Context) *LoginAccount {
	v := ctx.Value(LoginAccountKey)
	if account, ok := v.(*LoginAccount); ok {
		return account
	}
	return nil
}

func (util *LoginAccountUtil) SetUser(ctx context.Context, account *LoginAccount) context.Context {
	return context.WithValue(ctx, LoginAccountKey, account)
}
